package com.example.demo.model.user.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.model.user.user.entity.UserAddress;
import com.example.demo.model.user.user.mapper.UserAddressDao;
import com.example.demo.model.user.user.service.UserAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author STAHYW
 * @since 2021-10-20
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressDao, UserAddress> implements UserAddressService {

    @Autowired
    UserAddressDao userAddressDao;
    @Override
    public ModelAndView getUseraddress(HttpServletRequest request) {
        int userId = Integer.parseInt(request.getSession().getAttribute("userId").toString());
        QueryWrapper<UserAddress> queryWrapper = new QueryWrapper();
        queryWrapper.lambda().eq(UserAddress::getUserId,userId);
        List<UserAddress> userAddressList = userAddressDao.selectList(queryWrapper);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/userAddress/chooseAddress");
        modelAndView.addObject("userAddressList",userAddressList);
        return modelAndView;
    }
}
